{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Verifying the MLOps environment on GCP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Listing the installed packages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install -U -q pip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip list | grep 'tfx\\|kfp\\|beam\\|tensorflow'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Connecting to KFP and listing experiments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "\n",
    "PREFIX=<YOUR-PREFIX>\n",
    "ZONE=<YOUR-ZONE>\n",
    "NAMESPACE=<YOUR-NAMESPACE>\n",
    "\n",
    "gcloud container clusters get-credentials $PREFIX-cluster --zone $ZONE\n",
    "\n",
    "echo \"https://\"$(kubectl describe configmap inverse-proxy-config -n $NAMESPACE | \\\n",
    "grep \"googleusercontent.com\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use the URL produced by the previous cell as the **HOST_URL**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import kfp\n",
    " \n",
    "HOST_URL = ''\n",
    "NAMESPACE = 'kfp' # Change to your namespace\n",
    "  \n",
    "client = kfp.Client(host=HOST_URL, namespace=NAMESPACE)\n",
    "[pipeline.name for pipeline in client.list_pipelines().pipelines]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Connectiong to Cloud SQL ML Metadata and list tables\n",
    "[This page](https://cloud.google.com/sql/docs/mysql/connect-admin-proxy) describes how to connect a mysql client to your Cloud SQL instance using the Cloud SQL Proxy."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install -U -q mysql-connector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import mysql.connector\n",
    "\n",
    "metadb = mysql.connector.connect(\n",
    "    host='127.0.0.1',\n",
    "    port=3306,\n",
    "    database='metadb',\n",
    "    user=\"root\",\n",
    "    passwd=\"\" # set root password \n",
    ")\n",
    "\n",
    "cursor = metadb.cursor(buffered=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cursor.execute(\"SHOW TABLES FROM metadb;\")\n",
    "cursor.fetchall()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
